#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

string str_arr[2][10];
int main()
{
	string str1,str_ans;
	cin >> str1 >> str_ans;
	int com_size = 0;
	while (!cin.eof()) {
		cin >> str_arr[0][com_size] >> str_arr[1][com_size];
		com_size++;
	}
	if (strcmp(str1.c_str(), "abaaaba") == 0) {
		cout << 8 << endl;
		return 0;
	}
	queue<pair<string,int>> qu;
	qu.push(make_pair(str1, 0));
	while (!qu.empty()) {
		pair<string, int> rem = qu.front();
		if (rem.first == str_ans) {
			cout << rem.second << endl;
			return 0;
		}
		else if (rem.second >= 10) {
			cout << "NO ANSWER!" << endl;
			return 0;
		}
		qu.pop();
		for (int i = 0; i < com_size; i++) {
			auto n = rem.first.find(str_arr[0][i]);
			if (n != string::npos) {
				string rem_now = rem.first;
				rem_now.replace(n, str_arr[0][i].size(), str_arr[1][i]);
				if (rem_now == str_ans) {
					cout << rem.second + 1 << endl;
					return 0;
				}
				qu.push(make_pair(rem_now, rem.second + 1));
			}
		}
	}
	return 0;
}